package com.hanamaki.day1.day211025;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class demo2 {
    //注册驱动
    WebDriver driver;
    public void setUp(){
        //注册本地火狐打开位置
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        //初始化
        driver = new FirefoxDriver();
    }
    @Test
    public void test(){
        driver.get("file:///C:/Users/Administrator/Desktop/testhtml/exam/index.html");
        WebElement element = driver.findElement(By.xpath("//input[@value='Alert']"));
        element.click();
        Alert alert = driver.switchTo().alert();
        alert.accept();
    }
    @AfterMethod
    public void close(){
        driver.close();
    }

}
